package com.bigShen.pattern.proxy.shenProxy;

import com.bigShen.pattern.proxy.shenProxy.source.ShenClassLoader;
import com.bigShen.pattern.proxy.shenProxy.source.ShenInvocationHandler;
import com.bigShen.pattern.proxy.shenProxy.source.ShenProxy;

import java.lang.reflect.Method;

/**
 * @author: lei.shen
 * @date: 2018/10/3
 */
public class ShenLoveAgent implements ShenInvocationHandler {

    private Object element;

    public Object getInstance(Object element) {

        this.element = element;
        Object obj = ShenProxy.newProxyInstance(new ShenClassLoader(), element.getClass().getInterfaces(), this);
        return obj;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {

        System.out.println("Before : Shen 氏婚介所，帮寻找属于您的爱情!");
        method.invoke(element, args);
        System.out.println("After : Shen 氏婚介所, 姻缘已到, 收钱收工!");
        return null;
    }

}
